package com.grape.transaction.service.impl;

import com.grape.transaction.constant.Constants;
import com.grape.transaction.entity.MessageEntity;
import com.grape.transaction.service.MessageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 描述:MessageServiceImpl 独立消息服务
 * @author: myx
 * @date: 2019/6/12 0012
 * Copyright © 2019-grape. All rights reserved.
 */
@Service(value = "messageServiceImpl")
public class MessageServiceImpl implements MessageService {

	@Override
	@Transactional
	public void receiveMsg(MessageEntity message) {
		if (message == null) {
			throw new RuntimeException("消息为空");
		}

		switch (message.getStatus()) {
		case Constants.MessageStatus.INIT:
			// TODO save msg
			System.out.println("保存初始消息");
			break;
		case Constants.MessageStatus.SENT:
			// TODO update msg status 为sent
			// TODO 发送消息到订单减库存队列
			System.out.println("更新消息状态为sent");
			break;
		case Constants.MessageStatus.END:
			// TODO update msg status 为end
			break;

		default:
			throw new RuntimeException("消息状态有误");
		}
	}
}